package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PersonnelService;
import com.yixun.qfbao.apidto.RegistReqDto;
import com.yixun.qfbao.apidto.RegistResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.RegistReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author guifang.weng
 * @create 2017-12-05 20:43
 **/
@Service
public class RegistHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(RegistHander.class);

    @Autowired
    private PersonnelService personnelService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<RegistResDto> res = new BaseResponseDTO<>();
        RegistReqVo reqVo = (RegistReqVo)reqDto;
        RegistReqDto registReqDto = reqVo.getParams();
        try {
            RegistResDto resDto = personnelService.regist(registReqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
            res.setErrorMsg(resDto.getResultMsg());
        } catch (Exception e) {
            logger.error("RegistHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("注册失败");
        }
        return res;
    }
}
